-- Delete database entries for languages which were deleted in the past

DELETE a.* FROM gx_lang_configurations AS a LEFT JOIN languages l ON (a.`language_id` = l.`languages_id`) WHERE l.`languages_id` IS NULL;
DELETE a.* FROM content_manager_history AS a LEFT JOIN languages l ON (a.`languages_id` = l.`languages_id`) WHERE l.`languages_id` IS NULL;
DELETE a.* FROM cookie_consent_panel_purposes AS a LEFT JOIN languages l ON (a.`language_id` = l.`languages_id`) WHERE l.`languages_id` IS NULL;
DELETE a.* FROM export_schemes AS a LEFT JOIN languages l ON (a.`languages_id` = l.`languages_id`) WHERE a.`languages_id` != 0 AND l.`languages_id` IS NULL;
DELETE a.* FROM export_types AS a LEFT JOIN languages l ON (a.`language_id` = l.`languages_id`) WHERE l.`languages_id` IS NULL;
DELETE a.* FROM google_export_availability AS a LEFT JOIN languages l ON (a.`language_id` = l.`languages_id`) WHERE l.`languages_id` IS NULL;
DELETE a.* FROM google_export_condition AS a LEFT JOIN languages l ON (a.`language_id` = l.`languages_id`) WHERE l.`languages_id` IS NULL;
DELETE a.* FROM product_image_list_image_text AS a LEFT JOIN languages l ON (a.`language_id` = l.`languages_id`) WHERE l.`languages_id` IS NULL;
DELETE a.* FROM shipping_and_payment_matrix AS a LEFT JOIN languages l ON (a.`language_id` = l.`languages_id`) WHERE l.`languages_id` IS NULL;
DELETE a.* FROM slide_images AS a LEFT JOIN languages l ON (a.`language_id` = l.`languages_id`) WHERE l.`languages_id` IS NULL;
DELETE a.* FROM slides AS a LEFT JOIN languages l ON (a.`language_id` = l.`languages_id`) WHERE l.`languages_id` IS NULL;
DELETE a.* FROM static_seo_url_contents AS a LEFT JOIN languages l ON (a.`language_id` = l.`languages_id`) WHERE l.`languages_id` IS NULL;

UPDATE `agreements` SET `language_id` = 0 WHERE `language_id` NOT IN (SELECT `languages_id` FROM languages);
UPDATE `orders_parcel_tracking_codes` SET `language_id` = 0 WHERE `language_id` NOT IN (SELECT `languages_id` FROM languages);

DELETE FROM `gx_configurations` WHERE `key` = 'configuration/configuration/MODULE_PAYMENT_INSTALLED';

ALTER TABLE `orders` CHANGE `payment_method` `payment_method` VARCHAR(255) NOT NULL DEFAULT '', CHANGE `payment_class` `payment_class` VARCHAR(255) NOT NULL DEFAULT '', CHANGE `shipping_class` `shipping_class` VARCHAR(255) NOT NULL DEFAULT '';
UPDATE `orders` SET `payment_method` = 'swixpostfinancecheckout_creditdebitcard', `payment_class` = 'swixpostfinancecheckout_creditdebitcard' WHERE `payment_method` = 'swixpostfinancecheckout_creditde';
UPDATE `orders` SET `payment_method` = 'swixpostfinancecheckout_postfinancecard', `payment_class` = 'swixpostfinancecheckout_postfinancecard' WHERE `payment_method` = 'swixpostfinancecheckout_postfina';
